/**
 * 
 */
package com.sms.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.sms.vo.UserVO;

/**
 * @author Sahdev Kamboj
 * 
 */
public class UserValidator implements Validator {

	@Override
	public boolean supports(Class<?> classes) {
		return UserVO.class.isAssignableFrom(classes);
	}

	@Override
	public void validate(Object tarObject, Errors errors) {
		UserVO user = (UserVO) tarObject;
		
		if(user != null){
			if(user.getUserName().isEmpty()){
				errors.reject("username.empty", "userName");	
			}
			
			if(user.getUserPassword().isEmpty()){
				errors.reject("userpassword.empty", "userPassword");	
			}
			if(!user.getUserPassword().isEmpty() && user.getUserPassword().length() < 4){
				errors.reject("userpassword.length", "userPassword");	
			}
			
		}
		
	}
}
